package com.ruoyi.fly.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.fly.domain.Product;
import com.ruoyi.fly.domain.ProductCategory;
import com.ruoyi.fly.domain.vo.ProductCategoryVo;
import com.ruoyi.fly.domain.vo.ProductVo;
import com.ruoyi.fly.domain.vo.StoreProductVo;
import com.ruoyi.fly.domain.vo.StoreServerVo;
import com.ruoyi.fly.service.ProductCategoryService;
import com.ruoyi.fly.service.ProductService;
import com.ruoyi.fly.service.StoreProductService;
import com.ruoyi.fly.service.StoreServerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/productCategory")
@Api(tags = "产品管理")
public class ProductController extends BaseController {


    @Autowired
    private ProductCategoryService productCategoryService;

    @Autowired
    private ProductService productService;



    /**
     * 查询产品分类列表
     */
    @ApiOperation(value = "查询产品分类列表")
    @PostMapping("/categoryList")
    public TableDataInfo categoryList(ProductCategory productCategory) {
        startPage();
        List<ProductCategory> list = productCategoryService.selectProductCategoryList(productCategory);
        return getDataTable(list);
    }

    /**
     * 获取产品分类详细信息
     */
    @ApiOperation(value = "根据id获取产品分类详细信息")
    @GetMapping(value = "/sel/{id}")
    public R selectCategoryById(@PathVariable("id") String id) {
        if(productCategoryService.selectProductCategoryById(id)==null){
            return R.fail("产品分类不存在");
        }
        return R.ok(productCategoryService.selectProductCategoryById(id));
    }

    /**
     * 新增产品分类
     */
    @ApiOperation(value = "新增产品分类")
    @PostMapping("/insertCategory")
    public R addCategory(@RequestBody ProductCategoryVo productCategoryVo) {
        return productCategoryService.insertProductCategory(productCategoryVo);
    }

    /**
     * 修改产品分类
     */
    @ApiOperation(value = "修改产品分类")
    @PostMapping("/update")
    public R editCategory(@RequestBody ProductCategoryVo productCategoryVo) {
        return productCategoryService.updateProductCategory(productCategoryVo);
    }

    /**
     * 删除产品分类
     */
    @ApiOperation(value = "删除产品分类")
    @PostMapping("/delete/{ids}")
    public R removeCategory(@PathVariable String[] ids) {
        return productCategoryService.deleteProductCategoryByIds(ids);
    }


    /**
     * 查询商品列表
     */
    @ApiOperation(value = "查询商品列表")
    @PostMapping("/selProductList")
    public TableDataInfo productList(Product product) {
        startPage();
        List<Product> list = productService.selectProductList(product);
        return getDataTable(list);
    }

    /**
     * 根据id获取商品详细信息
     */
    @ApiOperation(value = "根据id获取商品详细信息")
    @GetMapping(value = "/selectProductById/{id}")
    public R selectProductById(@PathVariable("id") String id) {
        return R.ok(productService.selectProductById(id));
    }

    /**
     * 新增商品
     */
    @ApiOperation(value = "新增商品")
    @PostMapping("/addProduct")
    public R addProduct(@RequestBody ProductVo productVo) {
        return productService.insertProduct(productVo);
    }

    /**
     * 上架商品
     */
    @ApiOperation(value = "上架商品")
    @PostMapping("/onlineProduct")
    public R onlineProduct(@RequestBody ProductVo productVo) {
        return productService.onlineProduct(productVo);
    }

    /**
     * 下架商品
     */
    @ApiOperation(value = "下架商品")
    @PostMapping("/offlineProduct")
    public R offlineProduct(@RequestBody ProductVo productVo) {
        return productService.offlineProduct(productVo);
    }

    /**
     * 修改商品
     */
    @ApiOperation(value = "修改商品")
    @PostMapping("/editProduct")
    public R editProduct(@RequestBody ProductVo productVo) {
        return productService.updateProduct(productVo);
    }

    /**
     * 删除商品
     */
    @ApiOperation(value = "删除商品")
    @PostMapping("/deleteProduct/{ids}")
    public R removeProduct(@PathVariable String[] ids) {
        return productService.deleteProductByIds(ids);
    }



}
